#coding:utf8
import app_setting
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from db_base.TournamentServer import TM
def generate_auth_token( user_id,expiration = 60000):
    s = Serializer(app_setting.SECRET_KEY,expires_in = expiration)
    print s
    return s.dumps({ 'id': user_id })
def verify_auth_token(token):
    s = Serializer(app_setting.SECRET_KEY)
    try:
        data = s.loads(token)
    except Exception as e:
        return None # valid token, but expired
    user = TM.select('users',dict(id = data.get('id')),field = [' id , nickname, icon'])
    return data